package com.peng.leetcode.slidingWindow;

import java.util.LinkedList;

/**
 * MaxSlidingWindow
 * 剑指 Offer 59 - I. 滑动窗口的最大值
 * https://leetcode.cn/problems/hua-dong-chuang-kou-de-zui-da-zhi-lcof/
 *
 * @author: lupeng6
 * @create: 2023/2/24 11:09
 */
public class MaxSlidingWindow {

    public int[] maxSlidingWindow(int[] nums, int k) {
        if (nums == null || nums.length == 0) {
            return new int[0];
        }
        int[] ans = new int[nums.length - k + 1];
        for (int i = 0; i < nums.length - k + 1; i++) {
            ans[i] = searchMax(nums, i, i + k);
        }
        return ans;
    }

    private int searchMax(int[] nums, int start, int end) {
        int max = nums[start];
        for (int i = start; i < end; i++) {
            max = Math.max(max, nums[i]);
        }
        return max;
    }


}
